package com.haoze.nurse.enumeration;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class InOutValueTypeEnum {

    private String enumValue;
    private String enumName;
    private String enumType; // 引用类型标识
    private String enumVarCode; // 当前统计类型绑定的varCode
    private String varCode;
    public final static Map<String, InOutValueTypeEnum> enumMap = new HashMap();

    /**
     * 出入量总结
     */
    public final static InOutValueTypeEnum IN_OUT_SUMMARY = new InOutValueTypeEnum("0","出入量总结", "0", "crlzj","inoutsum");
    /**
     * 2小时出入量
     */
    public final static InOutValueTypeEnum IN_OUT_2HOURS = new InOutValueTypeEnum("1","2小时出入量", "4", "lxscrl","twosum");
    /**
     * 本班出入量
     */
    public final static InOutValueTypeEnum IN_OUT_8HOURS = new InOutValueTypeEnum("2","本班出入量", "5", "bbcrl","eigsum");
    /**
     * 本班出量
     */
    public final static InOutValueTypeEnum OUT_8HOURS = new InOutValueTypeEnum("3","本班出量", "6", "bbcl","eigout");
    /**
     * 24小时出量
     */
    public final static InOutValueTypeEnum OUT_24HOURS = new InOutValueTypeEnum("4","24小时出量", "7", "mtcl","tfout");
    /**
     * 本班尿量
     */
    public final static InOutValueTypeEnum URINE_OUT_8HOURS = new InOutValueTypeEnum("5","本班尿量", "8", "bbnl","eigurine");
    /**
     * 24小时尿量
     */
    public final static InOutValueTypeEnum URINE_OUT_24HOURS = new InOutValueTypeEnum("6","24小时尿量", "9", "mtnl","tfurine");
    /**
     * 本班冲洗出入量
     */
    public final static InOutValueTypeEnum WASH_IN_OUT_8HOURS = new InOutValueTypeEnum("7","本班冲洗出入量", "10", "bbcxcrl","eigrinse");

    /**
     * 24小时冲洗出入量
     */
    public final static InOutValueTypeEnum WASH_IN_OUT_24HOURS = new InOutValueTypeEnum("8","24小时冲洗出入量", "11", "mtcxcrl","tfrinse");

    private InOutValueTypeEnum(String enumValue, String enumName, String enumType, String enumVarCode,String varCode){
        this.enumValue = enumValue;
        this.enumName = enumName;
        this.enumType = enumType;
        this.enumVarCode = enumVarCode;
        this.varCode = varCode;
    }

    public static InOutValueTypeEnum fromValue(String enumValue){
//        if (enumMap.get(enumValue)==null) {
            putSourceEnum();
//        }
        return enumMap.get(enumValue);
    }

    public static void putSourceEnum(){

        Class clazz = InOutValueTypeEnum.class;
        Field[] fields = clazz.getDeclaredFields();
        InOutValueTypeEnum enumClass = null;
        for(Field field : fields) {
            if(field.getType().equals(clazz)) {
                try {
                    field.setAccessible(true);
                    enumClass = (InOutValueTypeEnum)field.get(null);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                if(enumClass != null) {
                    enumMap.put(enumClass.getEnumValue(),enumClass);
                }
            }
        }
    }


//    public static InOutValueTypeEnum fromType(String enumType){
//        if(enumMap.size() == 0) {
//            putTypeSourceEnum();
//        }
//        return enumMap.get(enumType);
//    }

//    public static void putTypeSourceEnum(){
//
//        Class clazz = InOutValueTypeEnum.class;
//        Field[] fields = clazz.getDeclaredFields();
//        InOutValueTypeEnum enumClass = null;
//        for(Field field : fields) {
//            if(field.getType().equals(clazz)) {
//                try {
//                    field.setAccessible(true);
//                    enumClass = (InOutValueTypeEnum)field.get(null);
//                } catch (IllegalAccessException e) {
//                    e.printStackTrace();
//                }
//                if(enumClass != null) {
//                    enumMap.put(enumClass.getEnumType(),enumClass);
//                }
//            }
//        }
//    }


    public String getEnumValue() {
        return enumValue;
    }

    public String getEnumName() {
        return enumName;
    }

    public String getEnumType() {
        return enumType;
    }

    public String getEnumVarCode() {
        return enumVarCode;
    }

    public String getVarCode(){
        return varCode;
    }
}
